<?php

namespace app\validate;

use app\Validate;

class Weapp extends Validate
{
    /**
     * 验证场景.
     *
     * @var array<array<string>>
     */
    protected $scene = [
        'login' => ['mobile', 'password'],  // 密码登录
        'signup' => ['mobile', 'smscode'],
        'session' => ['code'],
        'bind' => ['mobile', 'smscode', 'openid'],  // 密码登录
    ];
    /**
     * 验证规则.
     *
     * @var array<string>
     */
    protected $rule = [
        'mobile' => 'require|unique:user|exists:user|regex:/^1[35789]\d{9}$/i',  // 手机号
        'code'  => 'require|max:16',  // 请求码
        'smscode'  => 'require|length:6|smscode',  // 短信动态码
        'captcha'  => 'require',  // 验证码
        'openid' => 'require',
    ];
    /**
     * 验证字段描述
     * 
     * @var array<string>
     */
    protected $field = [
        'mobile' => '手机号',
        'code' => 'Code',
        'smscode' => '短信验证码',
        'captcha' => '图像验证码',
    ];
    // login 验证场景定义
    public function sceneLogin()
    {
    	return $this->only($this->scene['login'])->remove('mobile', 'unique');
    }    
    // signup 验证场景定义
    public function sceneSignup()
    {
    	return $this->only($this->scene['signup'])->remove('mobile', 'exists');
    }    
    // forget 验证场景定义
    public function sceneForget()
    {
    	return $this->only($this->scene['forget'])->remove('mobile', 'unique');
    }    
    // bind 验证场景定义
    public function sceneBind()
    {
    	return $this->only($this->scene['forget'])->remove('mobile', 'exists')->remove('mobile', 'unique');
    }    
}